﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utilities.Common;
using BL.DataAccess;
using System.Data;
namespace BL.Entities
{
    public static class Cuota
    {
        public static Double GetValor()
        {

            DataTable dt = DataBase.Current.ExecuteSQL("select * from cuota");
            return Double.Parse(dt.Rows[0][0].ToString());
        }

       
        public static void setValorPorcentaje(Double valor)
        {

            DataTable dt = DataBase.Current.ExecuteSQL("update porcentajeCO set  porcentajeCO = "+valor);
                       
        }

         public static void setValorCuota(Double valor)
        {

            DataTable dt = DataBase.Current.ExecuteSQL("update Cuota set  valorCuota = " +valor);
                       
        }


        public static Double GetValorPorcentaje()
        {
            
            DataTable dt = DataBase.Current.ExecuteSQL("select * from porcentajeCO");

            double porc = Double.Parse(dt.Rows[0][0].ToString());
            return porc;
        }


        public static void GenerarCoutas()
        {
            Movimiento m;
            Double valorCuota = -GetValor();
            foreach (var item in ColeccionProfesionales.Current)
            {
                if (item.Activo == true)
                {
                    m = new Movimiento();
                    m.Concepto = "Couta Circulo Odontologico " + DateTime.Now.ToString("MMMM yyyy");
                    m.Fecha = DateTime.Now;
                    m.Monto = valorCuota;
                    m.Profesional = item;
                    m.Save();
                }
            }
        }
        public static bool ChequearCuota()
        { 
         string concepto="Couta Circulo Odontologico " + DateTime.Now.ToString("MMMM yyyy");
         DataTable dt =DataBase.Current.ExecuteSQL("Select * from Movimientos where Concepto='" + concepto + "'");
         if (dt.Rows.Count != 0)
         {

             return false;

         }
         return true;
        
        
        
        
        }

    }
}